﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security;

namespace NGE
{
    class WindowsAPI
    {
        /// <summary>
        /// 获取时间的精度
        /// </summary>
        /// <param name="PerformanceFrequency"></param>
        /// <returns></returns>
        //[SuppressUnmanagedCodeSecurity]
        [DllImport("kernel32")]
        public static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);
        
        /// <summary>
        /// 获取时间计数
        /// </summary>
        /// <param name="PerformanceCount"></param>
        /// <returns></returns>
        //[SuppressUnmanagedCodeSecurity]
        [DllImport("kernel32")]
        public static extern bool QueryPerformanceCounter(ref long PerformanceCount);
        /// <summary>
        /// PeekMessage - Checks if messages are waiting in the queue. No parameters are
        ///   actually used.
        /// </summary>
        /// <param name="msg">not used</param>
        /// <param name="hWnd">not used</param>
        /// <param name="messageFilterMin">not used</param>
        /// <param name="messageFilterMax">not used</param>
        /// <param name="flags">not used</param>
        /// <returns></returns>
        //[SuppressUnmanagedCodeSecurity]
        [DllImport("User32")]
        public static extern bool PeekMessage(out SystemMessage msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
        [DllImport("User32")]
        public static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);



        [DllImport("imm32")]
        //获得输入法名称
        public extern static int ImmGetDescription(IntPtr hKL, StringBuilder lpszDescription, int uBufLen);
        [DllImport("imm32")]
        //为句柄设置输入法句柄
        public static extern IntPtr ImmAssociateContext(IntPtr hWnd, IntPtr hIMC);
        [DllImport("imm32")]
        public static extern int ImmGetCompositionString(IntPtr hIMC, int dwIndex, byte[] lpBuf, int dwBufLen);

        [DllImport("imm32")]
        public static extern IntPtr ImmGetContext(IntPtr hWnd);

        [DllImport("imm32")]
        public static extern IntPtr ImmGetDefaultIMEWnd(IntPtr hWnd);

        [DllImport("imm32")]
        public static extern void ImmLockIMC(IntPtr hIMC);

        [DllImport("user32")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32")]
        public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

        [DllImport("user32")]
        public static extern void SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("user32")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32")]
        public static extern bool GetWindowRect(IntPtr hWnd, ref System.Drawing.Rectangle lpRect);

        [DllImport("user32")]
        public static extern int GetClassName(IntPtr hWnd, StringBuilder IpClassName, int nMaxCount);

        [DllImport("user32")]
        public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

        [DllImport("user32")]
        public static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        [DllImport("user32")]
        public static extern IntPtr GetParent(IntPtr hWnd);

        [DllImport("user32")]
        public static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
    }
}
